Beaker = Button.extend({
	ctor:function(parent, zIndex, tag, callback, back){
		this._super(parent, zIndex, tag, "#beaker/beaker.png", callback, back);
		this.initBeaker();
	},
	initBeaker:function(){
		// 水位线
		var line = new cc.Sprite("#beaker_line.png");
		line.setOpacity(0);
		line.setPosition(this.width * 0.5, line.height * 0.5 + 5);
		this.addChild(line, 5, TAG_BEAKER_LINE);
		
		// 沉淀
		var deposit = new cc.Sprite("#deposit.png");
		deposit.setPosition(this.width * 0.5, 18);
		deposit.setOpacity(0);
		this.addChild(deposit,8,TAG_BEAKER_DEPOSIT);
		// 盐
		var salt = new cc.Sprite("#salt5.png");
		salt.setPosition(32, 16);
		salt.setScale(0.6);
		salt.setOpacity(0);
		this.addChild(salt,8,TAG_BEAKER_SALT);
		
		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.callNext.retain();
		this.loadName();
	},
	loadName:function(){
		var name = "";
		switch (this.getTag()) {
		case TAG_BEAKER:
			name = "①";
			break;
		case TAG_BEAKER2:
			name = "②";
			break;
		case TAG_BEAKER3:
			name = "③";
			break;
		case TAG_BEAKER4:
			name = "④";
			break;
		}
		var nameLabel = new cc.LabelTTF(name, gg.fontName, 20);
		nameLabel.setColor(cc.color(0,0,0));
		nameLabel.setPosition(this.width * 0.5, 60);
		this.addChild(nameLabel);
	},
	showSalt:function(next){
		var salt = this.getChildByTag(TAG_BEAKER_SALT);
		var seq = null;
		if(next){
			seq = cc.sequence(cc.fadeTo(0.5,255),this.callNext);
		} else {
			seq = cc.sequence(cc.fadeTo(0.5,255));
		}
		salt.runAction(seq);
	},
	showDep:function(next){
		var deposit = this.getChildByTag(TAG_BEAKER_DEPOSIT);
		var seq = null;
		if(next){
			seq = cc.sequence(cc.fadeTo(0.5,255),this.callNext);
		} else {
			seq = cc.sequence(cc.fadeTo(0.5,255));
		}
		deposit.runAction(seq);
	},
	upLine:function(next){
		var line = this.getChildByTag(TAG_BEAKER_LINE);
		var show = cc.fadeTo(0.5,255);
		// 水位线上升
		var move = cc.moveBy(1.5,cc.p(0,this.height * 0.4));
		var seq = null;
		if(next){
			seq = cc.sequence(show, move, this.callNext);
		} else {
			seq = cc.sequence(show, move);
		}
		line.runAction(seq);
	},
	upLineResult:function(){
		var line = this.getChildByTag(TAG_BEAKER_LINE);
		line.setOpacity(255);
		line.setPositionY(this.height * 0.4 + line.getPositionY());
	},
	downLine:function(){
		var line = this.getChildByTag(TAG_BEAKER_LINE);
		if(line.getOpacity() == 0){
			line.setOpacity(255);
			line.setPosition(this.width * 0.5, line.height * 0.5 + this.height * 0.4 + 5);	
		}
		// 水位线下降
		var move = cc.moveBy(1.5,cc.p(0, -this.height * 0.4));
		var fade = cc.fadeTo(0.5,0);
		var seq = cc.sequence(move,fade);
		line.runAction(seq);
	},
	pour:/**
			 * 倒水
			 */
	function(){
		var line = this.getChildByTag(TAG_BEAKER_LINE);
		if(line.getOpacity() == 0){
			line.setOpacity(255);
			line.setPosition(this.width * 0.5, line.height * 0.5 + this.height * 0.4 + 5);	
		}
		var rotate = cc.rotateTo(0.8, 50);
		var move = cc.moveTo(0.8,cc.p(30,44));
		var scale = cc.scaleTo(0.8,1.35);
		var spawn = cc.spawn(rotate, move, scale);
		var seq = cc.sequence(spawn,cc.callFunc(function(){
			var move = cc.moveBy(1.5,cc.p(-16, -32));
			var scale = cc.scaleTo(1.5,0.5);
			var spawn = cc.spawn(move, scale);
			var fade = cc.fadeTo(0.5,0);
			var seq = cc.sequence(spawn,fade);
			line.runAction(seq);
		}, this));
		line.runAction(seq);
	},
	pour2:function(){
		var line = this.getChildByTag(TAG_BEAKER_LINE);
		if(line.getOpacity() == 0){
			line.setOpacity(255);
			line.setPosition(this.width * 0.5, line.height * 0.5 + this.height * 0.4 + 5);	
		}
		var rotate = cc.rotateTo(0.8, -50);
		var move = cc.moveTo(0.8,cc.p(30,38));
		var scale = cc.scaleTo(0.8,1.35);
		var spawn = cc.spawn(rotate, move, scale);
		var seq = cc.sequence(spawn,cc.callFunc(function(){
			var move = cc.moveBy(1.5,cc.p(20, -20));
			var scale = cc.scaleTo(1.5,0.5);
			var spawn = cc.spawn(move, scale);
			var fade = cc.fadeTo(0.5,0);
			var seq = cc.sequence(spawn,fade);
			line.runAction(seq);
		}, this));
		line.runAction(seq);		
	},
	stir:function(time){
		// 产生波纹
		var line = this.getChildByTag(TAG_BEAKER_LINE);
		line.setVisible(false);
		var line2 = new cc.Sprite("#beaker/line.png");
		line2.setPosition(line.getPosition());
		this.addChild(line2);
		
		var light = new cc.Sprite("#beaker/light.png");
		light.setPosition(line2.width * 0.5, 0);
		line2.addChild(light);
		
		var point = new cc.Sprite("#beaker/point.png");
		point.setScaleY(0.8);
		point.setPosition(light.width * 0.5, -point.height * 0.5);
		light.addChild(point);
		
		var seq = cc.sequence(cc.moveBy(0.2, cc.p(-15, 0)),cc.moveBy(0.4, cc.p(30, 0)),cc.moveBy(0.2, cc.p(-15, 0)));
		light.runAction(cc.repeatForever(seq));
		this.scheduleOnce(function(){
			line.setVisible(true);
			line2.removeFromParent(true);
		}, time);
	},
	waitDiss:function(next){
		// 等待溶解
		var salt = this.getChildByTag(TAG_BEAKER_SALT);
		var seq = null;
		if(next){
			seq = cc.sequence(cc.fadeTo(1.5,0),this.callNext);
		} else {
			seq = cc.sequence(cc.fadeTo(1.5,0));
		}
		salt.runAction(seq);
	},
	hide:function(delay,next){
		var seq = null;
		if(delay != null && next != null){
			seq = cc.sequence(cc.delayTime(delay),this.getParent().callKill,this.callNext);
		} else if(delay != null){
			seq = cc.sequence(cc.delayTime(delay),this.getParent().callKill);
		} else {
			seq = cc.sequence(cc.fadeTo(0.5,0));
		}
		this.setCascadeOpacityEnabled(true);
		this.runAction(seq);
	},
	dead:function(){
		
	},
	onExit:function(){
		this._super();
		this.callNext.release();
	}
});